﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using QuanLiThuVien.Source;
using QuanLiThuVien.LinkModel;
using System.Data;

namespace QuanLiThuVien
{
    /// <summary>
    /// Interaction logic for BaoCaoMuonSach.xaml
    /// </summary>
    public partial class BaoCaoMuonSach : Page
    {
        private InsertInfo m_insertInfo = new InsertInfo();
        private UpdateInfo m_updateInfo = new UpdateInfo();
        private DeleteInfo m_deleteInfo = new DeleteInfo();
        private ShowInfo m_showInfo = new ShowInfo();
        private XuLyThem m_XuLyKhac = new XuLyThem();

        private THUVIEN.Service1 serv = new THUVIEN.Service1();

        private string m_sMaBCMS;

        public BaoCaoMuonSach()
        {
            InitializeComponent();
            addComboboxThang();
            addComboxNam();
        }

        private void addComboboxThang()
        {
            for (int i = 1; i < 13; i++ )
                cmbThangBC.Items.Add(i.ToString());
        }

        private void addComboxNam()
        {
            for (int i = 2000; i <= DateTime.Now.Year; i++)
                cmbNamBC.Items.Add(i.ToString());
        }

        private void bntBCMS_Click(object sender, RoutedEventArgs e)
        {
            if (cmbNamBC.SelectedItem == null || cmbThangBC.SelectedItem == null)
                MessageBox.Show("Phải chôn đầy đủ thông tin để báo cáo", "Thông báo");
            else
            {
                int m_iThang = Int32.Parse(cmbThangBC.SelectedItem.ToString());
                int m_iNam = Int32.Parse(cmbNamBC.SelectedItem.ToString());
                int m_iTongLuotMuon = serv.CountTongLuotMuon(m_iThang, m_iNam);
                m_sMaBCMS = serv.InsertBCMuonSach(m_iThang, m_iNam, m_iTongLuotMuon);

                for (int i = 0; i < serv.ListMaTheLoai().Length; i++)
                {
                    int m_iLuotMuonTheoTheLoai = serv.CountLuotMuonTheoTheLoai(m_iThang, m_iNam, serv.ListMaTheLoai()[i]);
                    float m_fTile = (float)(m_iLuotMuonTheoTheLoai * 100) / (float)m_iTongLuotMuon;
                    m_insertInfo.InsertCTBCMuonSach(m_sMaBCMS, serv.ListMaTheLoai()[i], m_iLuotMuonTheoTheLoai, m_fTile);
                }

                m_showInfo.SelectBCMuonSach(dataBaoCaoMS, m_sMaBCMS);
            }
        }

        private void bntXuatBCMS_Click(object sender, RoutedEventArgs e)
        {
            DataSet dataSet = new DataSet();
            dataSet = serv.ExportBCMuonSach(m_sMaBCMS);
            Export.exportExcel("Báo cáo mượn sách theo thể loại", dataSet);
        }

    }
}
